package linc.fun.admin.service;


import com.google.common.collect.Maps;
import com.mzlion.easyokhttp.HttpClient;
import linc.fun.common.rest.http.annotation.RestMethod;
import linc.fun.common.rest.http.annotation.RestMethodArg;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author yqlin
 * @date 2022/5/5 15:11
 * @description
 */
@Service
public class TestService {

    static Map<Long, User> cache;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    static class User {
        private Long id;
        private String name;
        private BigDecimal money;
        private Long height;
        private List<Integer> list;
    }

    static {
        cache = Maps.newHashMap();
        User user = new User(1L, "a", BigDecimal.valueOf(123213), 100L, Arrays.asList(112, 121));
        User user2 = new User(2L, "a", BigDecimal.valueOf(123213), 100L, Arrays.asList(112, 121));
        User user3 = new User(3L, "a", BigDecimal.valueOf(123213), 100L, Arrays.asList(112, 121));
        cache.put(user.id, user);
        cache.put(user.id, user2);
        cache.put(user.id, user3);
    }

    /**
     * POST:
     * JSON:
     * {
     * "method": "test1",
     * "params": {
     * }
     * }
     */
    @RestMethod
    public List<User> test1() throws InterruptedException {
        String info = HttpClient.get("https://github.com/PanJiaChen/vue-element-admin").toString();
        String info2 = HttpClient.get("https://github.com/PanJiaChen/vue-element-admin").toString();
        String info3 = HttpClient.get("https://github.com/PanJiaChen/vue-element-admin").toString();
        return cache.values().stream().toList();
    }

    /**
     * POST:
     * JSON:
     * {
     * "method": "test2",
     * "params": {
     * "id":1
     * }
     * }
     */
    @RestMethod
    public User test2(@RestMethodArg Long id) {
        return cache.get(id);
    }

    @RestMethod
    public User test3(@RestMethodArg(required = false) Long id) {
        return cache.get(1L);
    }
}
